import { getGameConfig } from "../gameConfigMgr";
import { setConnAuthorized } from "../gameConnMgr";
import { ReqLogin, ResLogin } from "../shared/gameClient/protocols/PtlLogin";
import { checkGameLoginToken } from "../shared/gameCluster/gfConfigMgr";
import { apiErrorThenClose, GameApiCall } from "./base";

export async function ApiLogin(call: GameApiCall<ReqLogin, ResLogin>) {
    var sCfg = getGameConfig();
    var userInfo = await checkGameLoginToken(sCfg.gameServer.serverId, call.req.loginToken);
    if (!userInfo) {
        return apiErrorThenClose(call, "错误的token!");
    }
    setConnAuthorized(call.conn, userInfo);
    call.succ({
        connectionId:call.conn.connectionId,
    });
}